#!/bin/bash
: '
# 官方无现成的arm64包，源码手动编译。
apt-get install libssl-dev
# cmake增加-DWITH_PROTOBUF=system，采用现成的protobuf避免编译时56%处卡死内存耗尽问题。
apt-get install libprotobuf-dev protobuf-compiler
# cmake增加-DWITH_JDBC=ON，需安装mysql客户端
# apt-get install libmariadb-dev libmariadb-dev-compat

# 下载源码
git clone https://github.com/mysql/mysql-connector-cpp.git
cd mysql-connector-cpp
mkdir build && cd build

# 使用静态编译（避免依赖系统 Boost）
cmake .. -DBUILD_SHARED_LIBS=OFF -DBOOST_INCLUDE_DIR=/root/work/boost-1.88.0 -DBOOST_LIB_DIR=/root/work/boost-1.88.0/stage/Linux/ARM64/Release/lib -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="./dist" -DWITH_PROTOBUF=system 
make -j$(nproc)
make install
# Windows下已经复制了头文件
# cp -r ./dist/include/mysqlx/* /root/work/Bridge6/libs/include/mysqlx
cp -r ./dist/lib64/libmysqlcppconn8.so* /root/work/Bridge6/libs/lib/linux/Release/
cp -r ./dist/lib64/libmysqlcppconn8.so* /root/work/Bridge6/libs/lib/linux/Debug/

# 方案二
# root@59dc17f9c5f8:/workspace/mysql-connector-cpp/build# apt install -y libmysqlcppconn-dev
# Reading package lists... Done
# Building dependency tree... Done
# Reading state information... Done
# libmysqlcppconn-dev is already the newest version (1.1.12-4).
# 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

tar zxvf mysql-connector-c++-8.4.0-src.tar.gz -C ./
cd ./mysql-connector-c++-8.4.0-src
mkdir build_linux_r
cd build_linux_r
cmake.. -DCMAKE_INSTALL_PREFIX=./dist -DCMAKE_BUILD_TYPE=Release -DWITH_JDBC=true -DBoost_NO_SYSTEM_PATHS=ON -DBoost_INCLUDE_DIR=~/work/boost-1.88 -DBoost_LIBRARY_DIR=~/work/boost-1.88/stage/Linux/ARM64/Release/lib

cmake .. -DCMAKE_INSTALL_PREFIX=./dist -DCMAKE_BUILD_TYPE=Release -DWITH_JDBC=true -DBUILD_SHARED_LIBS=ON -DBoost_NO_SYSTEM_PATHS=ON -DBoost_INCLUDE_DIR=~/work/boost-1.88 -DBoost_LIBRARY_DIR=~/work/boost-1.88/stage/Linux/ARM64/Release/lib

最终方案 libmariadb-dev 无缝替代 mysqlcppconn
'
